package com.kc.data.common.utils;



import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;


@Slf4j
@Component
public class WeChatUtil {
    private  String appid = "wx728c11328342c8f9";
    private  String secret = "wx728c11328342c8f9";
    @Resource
    private WeChatProperties weChatProperties;

//    public WeChatDTO getWeChatInfo(String weChatCode) {
//        String url = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=" + appid + "&secret=" + secret + "&code=" + weChatCode + "&grant_type=authorization_code";
//        RestTemplate restTemplate = new RestTemplate();
//        String response = restTemplate.getForObject(url, String.class);
//        WeChatDTO weChatDTO = JSON.parseObject(response, WeChatDTO.class);
//        assert weChatDTO != null;
//        if (weChatDTO.getOpenid() == null) {
//            return weChatDTO;
//        }
//        String userUrl = "https://api.weixin.qq.com/sns/userinfo?openid=" + weChatDTO.getOpenid() + "&access_token=" + weChatDTO.getAccessToken() + "&lang=zh_CN";
//        String userResponse = restTemplate.getForObject(userUrl, String.class);
//        weChatDTO = JSON.parseObject(userResponse, WeChatDTO.class);
//        return weChatDTO;
//    }
}
